#include <iostream>
#include <spdlog/spdlog.h>
#include <spdlog/async.h>
#include <spdlog/sinks/stdout_color_sinks.h>

using namespace std;

void test()
{
    //设置全局的刷新策略
    //每秒刷新
    spdlog::flush_every(std::chrono::seconds(1));
    //设置全局的刷新时机
    spdlog::flush_on(spdlog::level::level_enum::debug);
    //设置全局的日志输出级别
    spdlog::set_level(spdlog::level::level_enum::debug);
    //初始化异步日志器输出线程配置,初始化32768的日志消息缓存和1个工作线程的线程池
    spdlog::init_thread_pool(3072,1);  
    auto logger = spdlog::stdout_color_mt<spdlog::async_factory>("async-logger");

    logger->set_pattern("[%n][%H:%M:%S][%t][%-8l] %v");
    //进行日志输出
    logger->trace("你好！{}", "小明");
    logger->debug("你好！{}", "小明");
    logger->info("你好！{}", "小明");
    logger->warn("你好！{}", "小明");
    logger->error("你好！{}", "小明");
    logger->critical("你好！{}", "小明");
    std::cout << "日志输出演示完毕！\n";
}

int main()
{
    test();

    return 0;
}